#include<bits/stdc++.h>
using namespace std;
#define Int int
#define int long long
const int N=1e6+4,K=24,inf=1e18+1;
int jc[N],n,m,a[N],dp[K+1][55462],sum[1<<K],cnt;
Int t[1<<K];
set<int> s;
void solve(int cnt,int m){
    if(n==cnt){
        a[cnt]=*s.begin();
        return;
    }
    if(s.empty()) return;
    for(auto i:s){
        // cerr<<cnt<<" "<<m<<" "<<jc[n-cnt]<<"\n";
        if(m>jc[n-cnt]) m-=jc[n-cnt];
        else{
            a[cnt]=i;
            s.erase(i);
            solve(cnt+1,m);
            return;
        }
    }
}
int dfs(int x,int s){
    if(sum[s]>n&&x>5) return jc[n-x];
    if(x==n) return dp[x][t[s]]=1;
    if(dp[x][t[s]]) return dp[x][t[s]];
    for(int i=1;i<=n;i++){
        if((1<<(i-1))&s) continue;
        if(sum[s]<=i&&s) continue;
        dp[x][t[s]]+=dfs(x+1,s|(1<<(i-1)));
        dp[x][t[s]]=min(dp[x][t[s]],inf+1);
        if(dp[x][t[s]]==inf+1) return dp[x][t[s]];
    }
    // bitset<6> b=s;
    // cerr<<x<<" "<<b<<" "<<dp[x][s]<<" "<<sum[s]<<"\n";
    return dp[x][t[s]];
}
void sol(int x,int s,int m){
    if(x==n) return;
    for(int i=1;i<=n;i++){
        if((1<<(i-1))&s) continue;
        if(sum[s]<=i&&s) continue;
        if(m>dfs(x+1,s|(1<<(i-1)))) m-=dfs(x+1,s|(1<<(i-1)));
        else{
            a[x+1]=i;
            sol(x+1,s|(1<<(i-1)),m);
            return;
        }
    }
}
signed main(){
    freopen("permutation.in","r",stdin);
    freopen("permutation.out","w",stdout);
    ios::sync_with_stdio(0);
    cin.tie(0),cout.tie(0);
    jc[0]=1;
    for(int i=1;i<=20;i++) jc[i]=jc[i-1]*i;
    cin>>n>>m;
    if(n>=25){
        a[1]=3;
        a[2]=1;
        a[3]=2;
        for(int i=4;i<n-19;i++) a[i]=i;
        for(int i=n-19;i<=n;i++) s.insert(i);
        solve(n-19,m);
        for(int i=1;i<=n;i++) cout<<a[i]<<" ";
        return 0;
    }
    for(int i=1;i<1<<n;i++)
        for(int j=1;j<=n;j++)
            if(i&(1<<(j-1))) sum[i]+=j;
    for(int i=1;i<1<<n;i++)
        if(sum[i]<=n||__builtin_popcount(i)<=5) t[i]=++cnt;
    // cerr<<cnt<<"\n";
    // return 0;
    // cout<<dfs(0,0)<<"\n";
    // cerr<<dfs(0,0)<<"\n";
    dfs(0,0);
    sol(0,0,m);
    for(int i=1;i<=n;i++) cout<<a[i]<<" ";
}